package top.suven.base.http.admin.sec.dao;

import org.apache.ibatis.annotations.*;
import top.suven.base.core.mybatis.crud.CommonCrudMapper;
import top.suven.base.http.admin.sec.model.AdminRole;
import top.suven.base.http.admin.sec.model.Role;

import java.util.List;

/**
 * @Title: RoleService.java
 * @Description: 角色的数据交互类
 * @author lixiangling
 * @date   2018/08/13 16:58:08
 * @version V1.0.0
 * ----------------------------------------------------------------------------
 *  modifyer    modifyTime                 comment
 *
 * ----------------------------------------------------------------------------
 *
 */
public interface RoleDao extends CommonCrudMapper<Role> {
    @Select("<script> " +
            "select b.* from  sec_admin_role a,sec_role b where a.role_code=b.role_code "+
            "and b.status='1' and b.enable_status='1' and a.status='1' and a.enable_status='1' and a.admin_code=#{adminCode} " +
            "</script>")
    @Results(
            id="role",
            value = {
                    @Result(column = "role_code" , property = "roleCode"),
                    @Result(column = "role_type" , property = "roleType"),
                    @Result(column = "role_desc" , property = "roleDesc"),
                    @Result(column = "role_name" , property = "roleName"),
                    @Result(column = "status" , property = "status"),
                    @Result(column = "reorder" , property = "reorder"),
                    @Result(column = "remark" , property = "remark"),
                    @Result(column = "enable_status" , property = "enableStatus")
            }
    )
    List<Role> getRoleValidListByAdminCode(AdminRole adminRole);
    /**
     * @Title: 删除角色信息
     * @Description:id @{Link Long[]}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 16:58:08
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
    @Update("<script> " +
            "UPDATE sec_role set status='0'"+
            "WHERE role_code IN " +
            "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
            "#{item} " +
            "</foreach> " +
            "</script>")
    void del(@Param("idList") List<String> idList);
    /**
     * @Title: 禁用角色信息
     * @Description:id @{Link Long}
     * @param
     * @return
     * @throw
     * @author lixiangling
     * @date 2018/08/13 16:58:08
     *  --------------------------------------------------------
     *  modifyer    modifyTime                 comment
     *
     *  --------------------------------------------------------
     */
     @Update("<script> " +
             "UPDATE sec_role  " +
             "SET role_code = #{enableStatus}  " +
             "WHERE user_id IN " +
             "<foreach item='item' index='index' collection='idList' open='(' separator=',' close=')'> " +
             "#{item} " +
             "</foreach> " +
             "</script>")
     void updateEnableStatus(@Param("enableStatus") String enableStatus, @Param("idList") List<String> idList);
}